***********************************************************************************
***	Replication file for:                                                     	***
*** Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of 			***
***	Being Widowed by War: A Life-Cycle Perspective.	     						***
***																				***
***	Journal of Public Economics                                                 ***
***   							                                                ***
*** Script:		1-allbus-prep-1980-86.do						   			 	***	
*** Purpose:	data preparation, ALLBUS wave 1980-86							***
***																				***
*** Tables:		---																***
***	Figures:	---																***
***********************************************************************************

* Preamble (unnecessary when executing run.do)
run "$widowsallbus/scripts/programs/_config.do"

************
* Code begins
************

*** Load corrected data (GESIS patch)
do "$widowsallbus/scripts/ZA1335_v1-0-0_patch.do"


*** Relabel, generate variables

*** Study and interview characteristics
gen interview_year = v2 
label var interview_year "Year of interview"


*** Parents

label define sdegreeflab 1 "low" 2 "medium" 3 "high" 4 "don't know/father unknown"
gen school_degree_father = 1 if inlist(v100, 1, 2, 3)
replace school_degree_father = 2 if v100 == 4
replace school_degree_father = 3 if inlist(v100, 5, 6)
replace school_degree_father = 4 if inlist(v100, 8, 0)
label values school_degree_father sdegreeflab
label var school_degree_father "Schoold degree father"
tab school_degree_father





*** Norms

** Importance of different areas of life

recode v337-v343 (97 99 0 = .)

gen importance_family = v337
gen importance_job = v338
gen importance_leisure = v339
gen importance_friends = v340
gen importance_relatives = v341
gen importance_religion = v342
gen importance_politics = v343

foreach x in family job leisure friends relatives religion politics{
	label var importance_`x' "Importance of `x' in life (1-7 scale)"
}


** Gender roles

recode v437-v442 (9 0 = .) 

gen d_work_mother_goodrel = 0 if inlist(v437, 1, 2)
replace d_work_mother_goodrel = 1 if inlist(v437, 3, 4)
label var d_work_mother_goodrel "Can working mother have as warm and trusting a relationship with her children as non-working mother?"

gen d_wife_help_husband = 0 if inlist(v438, 1, 2)
replace d_wife_help_husband = 1 if inlist(v438, 3, 4)
label var d_wife_help_husband "More important for the wife to help her husband than to pursue her own career?"

gen d_work_wife_harmschild = 0 if inlist(v439, 1, 2)
replace d_work_wife_harmschild = 1 if inlist(v439, 3, 4)
label var d_work_wife_harmschild "Will toddler suffer if mother is working?"

gen d_wife_household = 0 if inlist(v440, 1, 2)
replace d_wife_household = 1 if inlist(v440, 3, 4)
label var d_wife_household "Better for everyone if wife stays at home?"

gen d_work_mother_goodchild = 0 if inlist(v441, 1, 2)
replace d_work_mother_goodchild = 1 if inlist(v441, 3, 4)
label var d_work_mother_goodchild "Even good for a child if mother is working and not only concentrate on household?"

gen d_work_wife_amarriage = 0 if inlist(v442, 1, 2)
replace d_work_wife_amarriage = 1 if inlist(v442, 3, 4)
label var d_work_wife_amarriage "Should married woman refrain from working if number of jobs limited?"

gen index_groles_work = (d_work_mother_goodrel + (1 - d_wife_help_husband) + (1 - d_work_wife_harmschild) + (1 - d_wife_household) + d_work_mother_goodchild + (1 - d_work_wife_amarriage)) / 6
label var index_groles_work "Progessive norms about womens' work (0-1)"

gen d_wife_help_husband_r = (1 - d_wife_help_husband)
gen d_work_wife_harmschild_r = (1 - d_work_wife_harmschild)
gen d_wife_household_r = (1 - d_wife_household)
gen d_work_wife_amarriage_r = (1 - d_work_wife_amarriage)

egen index_groles_work_v2 = rowmean(d_work_mother_goodrel d_wife_help_husband_r d_work_wife_harmschild_r d_wife_household_r d_work_mother_goodchild d_work_wife_amarriage_r) 
label var index_groles_work_v2 "Progessive norms about womens' work (0-1), ignoring missings"

drop d_*_r


*** Demographic variables

recode v101 97 99 = .

gen birth_year = v2 - v101 /* Interview year minus age at interview */
label var birth_year "Birth year"
tab birth_year  

gen d_female = (v218 == 2)
label var d_female "Female?"
tab d_female 

gen years_schooling = 8 if inlist(v7, 1, 2)
replace years_schooling = 10 if v7 == 3
replace years_schooling = 12 if v7 == 4
replace years_schooling = 13 if v7 == 5
label var years_schooling "Years of schooling"


*** Define variables for marriage history

** Ever married?
recode v44 9 = .
gen d_ever_married = 0 if v44 == 5
replace d_ever_married = 1 if inlist(v44, 1, 2, 3, 4)
label var d_ever_married "Was person ever married?"
tab d_ever_married

** Married before end of WW2
recode v45 v69 (9997 9998 9999 = .)
gen d_married_b1945 = 0 if v45 != . & v69 != .
replace d_married_b1945 = 1 if inrange(v45, 1918, 1945) | inrange(v69, 1912, 1945)
label var d_married_b1945 "Was person married before end of WW2?"

** Year first marriage
gen year_marriage1 =  v45 if v45 != 0
replace year_marriage1 = v69 if (year_marriage1 == . & v69 != 0)   
label var year_marriage1 "Year of first marriage"

** Did spouse die during the war?

gen d_spouse_died_WW2 = (v50 == 2) | (v56 == 2) | (v74 == 2) | (v80 == 2) 
label var d_spouse_died_WW2 "Did spouse die during WW2"


*** Order variables

drop v1* v2* v3* v4* v5* v6* v7* v8* v9*

gen ___survey________________ = .
order ___survey________________ interview_year, first

gen ___demography____________ = .
order ___demography____________ birth_year d_female years_schooling, after(interview_year)  

gen ___marriagehist__________ = .
order ___marriagehist__________ d_ever_married year_marriage1 d_married_b1945 d_spouse_died_WW2, after(years_schooling)

gen ___parents_______________ = .
order ___parents_______________ school_degree_father, after(d_spouse_died_WW2) 

gen ___norms_pref____________ = .
gen ___life_areas____________ = .
order ___norms_pref____________ ___life_areas____________  importance_family importance_family importance_job importance_leisure importance_friends importance_relatives importance_religion importance_politics, after(school_degree_father)

gen ___gender_roles__________ = .
order ___gender_roles__________ index_groles_work index_groles_work_v2 d_work_mother_goodrel d_wife_help_husband d_work_wife_harmschild d_wife_household d_work_mother_goodchild d_work_wife_amarriage, after(importance_politics)


** Yes/no labels
label define yesno 0 "No" 1 "Yes"
label val d_* yesno  

*** Save

save "$widowsallbus/processed/allbus1980_86_edit.dta", replace



*** EOF